<?php
/*
** @introduction: 商品属性
** @author: 杨陈鹏
** @date: 2015-04-10 16:22
** @email: yangchenpeng@cdlinglu.com
*/

namespace Admin\Controller\Goods;


use Common\Controller\Admin\CommonController;

class AttrController extends CommonController
{
    /*
    ** @introduction: 属性列表
    ** @author: 杨陈鹏
    ** @date: 2015-04-10 16:22
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function lists()
    {

        $logic = D('Common/Attr', 'Logic');

        $this->data = $logic::getAttrData();

        $this->display();

    }

    /*
    ** @introduction: 添加属性
    ** @author: 杨陈鹏
    ** @date: 2015-04-10 16:22
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function create()
    {

        $data = I('post.data');

        if ($data) {

            $logic = D('Common/Attr', 'Logic');

            $this->ajaxReturn($logic::create($data));

        } else {

            $logic = D('Common/Category', 'Logic');
            //获取所有规则
            $categorys = $logic::getChilds(0, 'id,name,pid,child');

            //获取树型下拉框
            $tree = new \Org\Util\Tree();

            $tree->init($categorys);

            $this->category_tree = $tree->create(0, '<option value=$id $disabled>$spacer $name</option>', 0, '', true);

            $this->display();
        }

    }

    /*
    ** @introduction: 修改属性
    ** @author: 杨陈鹏
    ** @date: 2015-04-10 16:22
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function updateAttr()
    {

        $data = I('post.data');

        $logic = D('Common/Attr', 'Logic');

        $this->ajaxReturn($logic::updateAttr($data));

    }

    /*
    ** @introduction: 修改属性值
    ** @author: 杨陈鹏
    ** @date: 2015-04-10 16:22
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function updateAttrVal()
    {

        $data = I('post.data');

        $logic = D('Common/Attr', 'Logic');

        $this->ajaxReturn($logic::updateAttrVal($data));


    }

    /*
    ** @introduction: 删除属性
    ** @author: 杨陈鹏
    ** @date: 2015-04-10 16:22
    ** @email: yangchenpeng@cdlinglu.com
    */
    public function deleteAttr()
    {

        $id = I('post.data');

        $logic = D('Common/Attr', 'Logic');

        $this->ajaxReturn($logic::deleteAttr($id));

    }

    /**
     * @introduction: 删除属性值
     * @author: 杨陈鹏
     * @date: 2015-04-10 16:22
     * @email: yangchenpeng@cdlinglu.com
     */
    public function deleteAttrVal()
    {

        $data = I('post.data');

        $logic = D('Common/Attr', 'Logic');

        $this->ajaxReturn($logic::deleteAttrVal($data));


    }

    /**
     * @introduction: 查看属性值
     * @author: 杨陈鹏
     * @date: 2015-04-10 16:22
     * @email: yangchenpeng@cdlinglu.com
     */
    public function attrValLists()
    {

        $this->attr_id = I('post.id');

        $logic = D('Common/Attr', 'Logic');

        $this->data = $logic::getAttrVal($this->attr_id);

        if ($this->data['code'] == 300)
            $this->ajaxReturn($this->data);

        $this->data = $this->data['data'];


        $this->display();


    }

    /**
     * @introduction: 添加一个属性值
     * @author: 杨陈鹏
     * @date: 2015-04-10 16:22
     * @email: yangchenpeng@cdlinglu.com
     */
    public function createOneAttrVal()
    {

        $data = I('post.data');

        $logic = D('Common/Attr', 'Logic');

        $this->ajaxReturn($logic::createOneAttrVal($data));


    }


}